/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package Controller;

import Data.Prize;
import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 *
 * @author NGOCLINH-PC
 */
public class PrizePR extends HttpServlet {

    /**
     * Processes requests for both HTTP
     * <code>GET</code> and
     * <code>POST</code> methods.
     *
     * @param request servlet request
     * @param response servlet response
     * @throws ServletException if a servlet-specific error occurs
     * @throws IOException if an I/O error occurs
     */
    protected void processRequest(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        response.setContentType("text/html;charset=UTF-8");
        PrintWriter out = response.getWriter();
        try {
            if (request.getParameter("AprizeID") != null) {
                int idcate = Integer.parseInt(request.getParameter("AprizeID"));
                Prize.Pdelete(idcate);
            } else if (request.getParameter("txtPrizeID") != null) {
                int id = Integer.parseInt(request.getParameter("txtPrizeID"));
                String txtPrizeTypeID = request.getParameter("txtPrizeTypeID");
                String txtEvent = request.getParameter("txtEvent");
                String txtMember = request.getParameter("txtMember");
                String txtPrizeName = request.getParameter("txtPrizeName");
                int stt = Integer.parseInt(request.getParameter("radio1"));
                Prize.Pupdate(id, txtPrizeTypeID, txtEvent, txtMember, txtPrizeName, stt);
            } else {
                int txtPrizeTypeID = Integer.parseInt(request.getParameter("txtPrizeTypeID"));
                int txtEvent = Integer.parseInt(request.getParameter("txtEvent"));
                int txtMember = Integer.parseInt(request.getParameter("txtMember"));
                String txtPrizeName = request.getParameter("txtPrizeName");
                int stt = Integer.parseInt(request.getParameter("radio1"));
                Prize.Pinsert(txtPrizeTypeID, txtEvent, txtMember, txtPrizeName, stt);

            }
            response.sendRedirect("/nlpp/admin/index.jsp?page=Prize");
        } finally {
            out.close();
        }
    }

    // <editor-fold defaultstate="collapsed" desc="HttpServlet methods. Click on the + sign on the left to edit the code.">
    /**
     * Handles the HTTP
     * <code>GET</code> method.
     *
     * @param request servlet request
     * @param response servlet response
     * @throws ServletException if a servlet-specific error occurs
     * @throws IOException if an I/O error occurs
     */
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        processRequest(request, response);
    }

    /**
     * Handles the HTTP
     * <code>POST</code> method.
     *
     * @param request servlet request
     * @param response servlet response
     * @throws ServletException if a servlet-specific error occurs
     * @throws IOException if an I/O error occurs
     */
    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        processRequest(request, response);
    }

    /**
     * Returns a short description of the servlet.
     *
     * @return a String containing servlet description
     */
    @Override
    public String getServletInfo() {
        return "Short description";
    }// </editor-fold>
}
